/*
 * $Id: ipmc.h,v 1.46.6.2 Broadcom SDK $
 * 
 * $Copyright: Copyright 2011 Broadcom Corporation.
 * This program is the proprietary software of Broadcom Corporation
 * and/or its licensors, and may only be used, duplicated, modified
 * or distributed pursuant to the terms and conditions of a separate,
 * written license agreement executed between you and Broadcom
 * (an "Authorized License").  Except as set forth in an Authorized
 * License, Broadcom grants no license (express or implied), right
 * to use, or waiver of any kind with respect to the Software, and
 * Broadcom expressly reserves all rights in and to the Software
 * and all intellectual property rights therein.  IF YOU HAVE
 * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
 * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
 * ALL USE OF THE SOFTWARE.  
 *  
 * Except as expressly set forth in the Authorized License,
 *  
 * 1.     This program, including its structure, sequence and organization,
 * constitutes the valuable trade secrets of Broadcom, and you shall use
 * all reasonable efforts to protect the confidentiality thereof,
 * and to use this information only in connection with your use of
 * Broadcom integrated circuit products.
 *  
 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
 * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
 * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
 * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
 * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
 * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
 * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
 * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
 * 
 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
 * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
 * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
 * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
 * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR USD 1.00,
 * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
 * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
 * 
 * DO NOT EDIT THIS FILE!
 * This file is auto-generated.
 * Edits to this file will be lost when it is regenerated.
 */

#ifndef __BCM_IPMC_H__
#define __BCM_IPMC_H__

#if defined(INCLUDE_L3)

#include <bcm/types.h>
#include <bcm/l3.h>

/* IPMC address type. */
typedef struct bcm_ipmc_addr_s {
    bcm_ip_t s_ip_addr;                 /* IPv4 Source address. */
    bcm_ip_t mc_ip_addr;                /* IPv4 Destination address. */
    bcm_ip6_t s_ip6_addr;               /* IPv6 Source address. */
    bcm_ip6_t mc_ip6_addr;              /* IPv6 Destination address. */
    bcm_vlan_t vid;                     /* VLAN identifier. */
    bcm_vrf_t vrf;                      /* Virtual Router Instance. */
    bcm_cos_t cos;                      /* COS based on dst IP multicast addr. */
    bcm_pbmp_t l2_pbmp;                 /* L2 Port bitmap. */
    bcm_pbmp_t l2_ubmp;                 /* L2 Untag port bitmap. */
    bcm_pbmp_t l3_pbmp;                 /* L3 Port bitmap. */
    int ts;                             /* Source port or TGID bit. */
    int port_tgid;                      /* Source port or TGID. */
    int v;                              /* Valid bit. */
    int mod_id;                         /* Module ID. */
    int ipmc_index;                     /* Use this index to program IPMC table
                                           for XGS chips based on flags value.
                                           For SBX chips it is the Multicast
                                           Group index */
    uint32 flags;                       /* See BCM_IPMC_XXX flag definitions. */
    int lookup_class;                   /* Classification lookup class ID. */
    bcm_fabric_distribution_t distribution_class; /* Fabric Distribution Class. */
} bcm_ipmc_addr_t;

/* IPMC address flags. */
#define BCM_IPMC_KEEP_ENTRY                 0x00000001 /* Internal use. */
#define BCM_IPMC_USE_IPMC_INDEX             0x00000002 /* When set the ipmc
                                                          add/del functions use
                                                          the ipmc_index
                                                          supplied. */
#define BCM_IPMC_REPLICATE                  0x00000004 /* Add entry allowing
                                                          replication if
                                                          (supported). */
#define BCM_IPMC_HIT                        0x00000008 /* On get, indicates if
                                                          L3 hit is on for
                                                          entry. */
#define BCM_IPMC_SOURCE_PORT_NOCHECK        0x00000010 /* Do not source port
                                                          check this entry (XGS
                                                          only). */
#define BCM_IPMC_DISABLED                   0x00000020 /* Add entry in disabled
                                                          state. */
#define BCM_IPMC_REPLACE                    0x00000040 /* Replace an existing
                                                          entry. */
#define BCM_IPMC_IP6                        0x00000080 /* IPv6 support. */
#define BCM_IPMC_HIT_CLEAR                  0x00000100 /* Clear hit bit. */
#define BCM_IPMC_SETPRI                     0x00000200 /* Pick up new priority
                                                          (XGS3 only). */
#define BCM_IPMC_PROXY_IP6                  0x00000400 /* IPv6 Proxy MC egress
                                                          ports on XGS2. */
#define BCM_IPMC_ADD_DISABLED               BCM_IPMC_DISABLED 
#define BCM_IPMC_USE_FABRIC_DISTRIBUTION    0x00001000 /* Use specified fabric
                                                          distribution class. */
#define BCM_IPMC_COPYTOCPU                  0x00002000 /* When set, Copy the
                                                          packet to CPU. */

/* IPMC counters structure. */
typedef struct bcm_ipmc_counters_s {
    uint64 rmca;    /* Received L2 multicast frame. */
    uint64 tmca;    /* Transmit L2 multicast packet counter. */
    uint64 imbp;    /* Number of IPMC packets bridged. */
    uint64 imrp;    /* Number of IPMC packets routed. */
    uint64 rimdr;   /* Number of IPMC dropped in ingress. */
    uint64 timdr;   /* Number of IPMC dropped in egress. */
} bcm_ipmc_counters_t;

/* bcm_ipmc_traverse_cb */
typedef int (*bcm_ipmc_traverse_cb)(
    int unit, 
    bcm_ipmc_addr_t *info, 
    void *user_data);

#ifndef BCM_HIDE_DISPATCHABLE

/* Initialize the BCM IPMC subsystem. */
extern int bcm_ipmc_init(
    int unit);

/* Detach the BCM IPMC subsystem. */
extern int bcm_ipmc_detach(
    int unit);

/* Enable/disable IPMC support. */
extern int bcm_ipmc_enable(
    int unit, 
    int enable);

/* Enable/disable source port checking. */
extern int bcm_ipmc_source_port_check(
    int unit, 
    int enable);

/* Define the IPMC search rule. */
extern int bcm_ipmc_source_ip_search(
    int unit, 
    int enable);

#endif /* BCM_HIDE_DISPATCHABLE */

/* Initialize a bcm_ipmc_addr_t/bcmx_ipmc_addr_t. */
extern void bcm_ipmc_addr_t_init(
    bcm_ipmc_addr_t *data);

#ifndef BCM_HIDE_DISPATCHABLE

/* Add new IPMC group. */
extern int bcm_ipmc_add(
    int unit, 
    bcm_ipmc_addr_t *data);

/* Find info of an IPMC group. */
extern int bcm_ipmc_find(
    int unit, 
    bcm_ipmc_addr_t *data);

/* Remove IPMC group. */
extern int bcm_ipmc_remove(
    int unit, 
    bcm_ipmc_addr_t *data);

/* Remove all IPMC groups. */
extern int bcm_ipmc_remove_all(
    int unit);

/* Get an IPMC entry at a specified IPMC index. */
extern int bcm_ipmc_get_by_index(
    int unit, 
    int index, 
    bcm_ipmc_addr_t *data);

/* Delete IPMC group (API superceded). */
extern int bcm_ipmc_delete(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    int keep);

/* Delete all IPMC groups (API superceded). */
extern int bcm_ipmc_delete_all(
    int unit);

/* Get info of an IPMC group (API superceded). */
extern int bcm_ipmc_get(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    bcm_ipmc_addr_t *data);

/* Enable/Disable an IPMC group (API superceded). */
extern int bcm_ipmc_entry_enable_set(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    int enable);

/* Set the cos of an IPMC entry (API superceded). */
extern int bcm_ipmc_cos_set(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    int cos);

/* Set the input module ID of an IPMC entry (API superceded). */
extern int bcm_ipmc_port_modid_set(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    int mod_id);

/* Set the source port/trunk group ID of an IPMC entry (API superceded). */
extern int bcm_ipmc_port_tgid_set(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    int ts, 
    int port_tgid);

/* Add L2 multicast ports for IPMC group (API superceded). */
extern int bcm_ipmc_add_l2_ports(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    bcm_pbmp_t pbmp, 
    bcm_pbmp_t ut_pbmp);

/* Delete L2 multicasted ports from an IPMC entry (API superceded). */
extern int bcm_ipmc_delete_l2_ports(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    bcm_port_t port);

/* Add ports for L3 multicast to an IPMC entry (API superceded). */
extern int bcm_ipmc_add_l3_ports(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    bcm_pbmp_t pbmp);

/* Delete ports for L3 multicast from an IPMC entry (API superceded). */
extern int bcm_ipmc_delete_l3_port(
    int unit, 
    bcm_ip_t s_ip_addr, 
    bcm_ip_t mc_ip_addr, 
    bcm_vlan_t vid, 
    bcm_port_t port);

/* Reinitialize/clear the egress IP multicast configuration. */
extern int bcm_ipmc_egress_port_init(
    int unit);

/* Configure the IP Multicast egress properties. */
extern int bcm_ipmc_egress_port_set(
    int unit, 
    bcm_port_t port, 
    const bcm_mac_t mac, 
    int untag, 
    bcm_vlan_t vid, 
    int ttl_threshold);

/* Get the egress IP multicast configuration properties. */
extern int bcm_ipmc_egress_port_get(
    int unit, 
    bcm_port_t port, 
    bcm_mac_t mac, 
    int *untag, 
    bcm_vlan_t *vid, 
    int *ttl_threshold);

/* Get the combined IP multicast statistics. */
extern int bcm_ipmc_counters_get(
    int unit, 
    bcm_port_t port, 
    bcm_ipmc_counters_t *counters);

/* 
 * Provides maximum IPMC index that this fabric can handle
 * (BCM5670/BCM5675).
 */
extern int bcm_ipmc_bitmap_max_get(
    int unit, 
    int *max_index);

/* Set the IPMC forwarding port bitmap (BCM5670/BCM5675). */
extern int bcm_ipmc_bitmap_set(
    int unit, 
    int ipmc_idx, 
    bcm_port_t port, 
    bcm_pbmp_t pbmp);

/* Get the IPMC forwarding port bitmap (BCM5670/BCM5675). */
extern int bcm_ipmc_bitmap_get(
    int unit, 
    int ipmc_idx, 
    bcm_port_t port, 
    bcm_pbmp_t *pbmp);

/* Remove IPMC forwarding port bitmap (BCM5670/BCM5675). */
extern int bcm_ipmc_bitmap_del(
    int unit, 
    int ipmc_idx, 
    bcm_port_t port, 
    bcm_pbmp_t pbmp);

/* 
 * Return set of VLANs selected for port's replication list for IPMC
 * group (pre-XGS3).
 */
extern int bcm_ipmc_repl_get(
    int unit, 
    int index, 
    bcm_port_t port, 
    bcm_vlan_vector_t vlan_vec);

/* 
 * Add a VLAN (or L3 Interface id for XGS3) to selected ports'
 * replication list (pre-XGS3).
 */
extern int bcm_ipmc_repl_add(
    int unit, 
    int index, 
    bcm_pbmp_t pbmp, 
    bcm_vlan_t vlan);

/* 
 * Remove VLAN (or L3 Interface in the case of XGS3) from selected ports'
 * replication list (pre-XGS3).
 */
extern int bcm_ipmc_repl_delete(
    int unit, 
    int index, 
    bcm_pbmp_t pbmp, 
    bcm_vlan_t vlan);

/* 
 * Remove all VLANs (or L3 Interfaces in XGS3) from selected ports'
 * replication list (pre-XGS3).
 */
extern int bcm_ipmc_repl_delete_all(
    int unit, 
    int index, 
    bcm_pbmp_t pbmp);

/* 
 * Add an L3 Interface or VLAN to the egress port's replication list
 * (XGS3).
 */
extern int bcm_ipmc_egress_intf_add(
    int unit, 
    int mc_index, 
    bcm_port_t port, 
    bcm_l3_intf_t *l3_intf);

/* 
 * Remove L3 Interface or VLAN from the given egress port's replication
 * list (XGS3).
 */
extern int bcm_ipmc_egress_intf_delete(
    int unit, 
    int mc_index, 
    bcm_port_t port, 
    bcm_l3_intf_t *l3_intf);

/* 
 * Remove all L3 interfaces (or VLANs) from the given (egress) port's
 * replication list (XGS3).
 */
extern int bcm_ipmc_egress_intf_delete_all(
    int unit, 
    int mc_index, 
    bcm_port_t port);

#endif /* BCM_HIDE_DISPATCHABLE */

/* Initialize an IPMC counters structure (XGS3). */
extern void bcm_ipmc_counters_t_init(
    bcm_ipmc_counters_t *ipmc_counter);

#ifndef BCM_HIDE_DISPATCHABLE

/* 
 * Assign a set of VLANs as the selected port's replication list (compact
 * mode).
 */
extern int bcm_ipmc_repl_set(
    int unit, 
    int mc_index, 
    bcm_port_t port, 
    bcm_vlan_vector_t vlan_vec);

/* 
 * Assign a list of L3 Interfaces (or VLANS) to the egress port's
 * replication list (compact mode).
 */
extern int bcm_ipmc_egress_intf_set(
    int unit, 
    int mc_index, 
    bcm_port_t port, 
    int if_count, 
    bcm_if_t *if_array);

/* 
 * Assign a list of L3 Interfaces (or VLANS) to the egress port's
 * replication list (compact mode).
 */
extern int bcm_ipmc_egress_intf_get(
    int unit, 
    int mc_index, 
    bcm_port_t port, 
    int if_max, 
    bcm_if_t *if_array, 
    int *if_count);

/* Age unused ipmc table entries. */
extern int bcm_ipmc_age(
    int unit, 
    uint32 flags, 
    bcm_ipmc_traverse_cb age_cb, 
    void *user_data);

/* 
 * Traverse through the ipmc table and run callback at each valid ipmc
 * entry.
 */
extern int bcm_ipmc_traverse(
    int unit, 
    uint32 flags, 
    bcm_ipmc_traverse_cb cb, 
    void *user_data);

#endif /* defined(INCLUDE_L3) */

#endif /* BCM_HIDE_DISPATCHABLE */

#endif /* __BCM_IPMC_H__ */
